﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Chat.aspx.cs" Inherits="WebChat.Chat" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <title>Chat</title>
</head>
<body>
    <form id="formChat" runat="server">

    <asp:ScriptManager ID="ScriptManager" runat="server">
    </asp:ScriptManager>
    <h1>Mega Lite Chat by Subev</h1>
    <asp:Timer runat="server" ID="TimerRefreshChat" Interval="500" 
        ontick="TimerRefreshChat_Tick" />
    <asp:TextBox ID="TextBoxMessageToPost" runat="server" />
    <asp:Button ID="ButtonSend" Text="Send" runat="server" OnClick="ButtonSend_Click" />
    <br />

    <asp:UpdatePanel ID="UpdatePanelChat" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerRefreshChat" EventName="Tick" />
        </Triggers>
        <ContentTemplate>        
            <asp:ListView ID="ListviewMessages" runat="server" DataSourceID="EntityDataSourceMessages" >  
                <ItemTemplate>
                    <div><%# Server.HtmlEncode(Eval("Body").ToString()) %></div>
                </ItemTemplate>
            </asp:ListView>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:EntityDataSource ID="EntityDataSourceMessages" runat="server" ConnectionString="name=ChatDBEntities"
        DefaultContainerName="ChatDBEntities" EnableFlattening="False" EntitySetName="Messages" OrderBy="it.MessageID DESC"
        Select="TOP(20) it.[Body],it.MessageID">
    </asp:EntityDataSource>

    </form>
</body>
</html>
